<?php // no direct access
defined('_JEXEC') or die('Restricted access');


$udalosti_sablony_arr = $this->udalosti_sablony;
if (!empty($udalosti_sablony_arr['chyba'])) {
    echo '<h3>'.$udalosti_sablony_arr['chyba'].'</h3>';
} else {


    ?>
<style type="text/css">
    table.hlavni { border: 2px solid green; border-collapse:collapse; padding: 3px;
                   margin: 5px; text-align: center }
    p { text-indent: 30px; margin: 0px }
    th {border: 1px solid green; border-collapse:collapse}
    th.den_obyc {border: 1px solid green; border-collapse:collapse;
                 vertical-align:baseline; background-color:#99FF66; text-align:left}
    th.den_dnes {border: 1px solid green; border-collapse:collapse;
                 vertical-align:baseline; background-color:#CCFFCC; text-align:left}
    td {border: 1px solid green; border-collapse:collapse}
    td.den_obyc {border: 1px solid green; border-collapse:collapse;
                 background-color:#99FF66}
    td.den_dnes {border: 1px solid green; border-collapse:collapse;
                 background-color:#CCFFCC}
    table.dolni { border-width:0px; border-collapse:collapse; padding: 3px;
                  margin-top: 25px; text-align: center }
    td.dolni { border-width:0px; border-collapse:collapse; padding-left:20px}
    th.dolni { border-width:0px; border-collapse:collapse; padding-left:20px}
    div.udalost { padding-bottom: 10px; padding-top:3px; padding-left:5px;
                  padding-right:5px}
    span.black {color:black}
    span.red {color:red}
    span.green {color:green}
    span.blue {color:blue}
    span.purple {color:purple}
    span.gold {color:gold}
    span.hotPink {color:hotPink}
</style>
<table class="hlavni">

        <?php
        $bunky_arr = $udalosti_sablony_arr['bunky_arr'];
        $dny_tydne_arr = array('PO','UT','ST','CT','PA','SO','NE');
        $mista_arr = $udalosti_sablony_arr['mista_arr'];
        $mista_id_arr = $udalosti_sablony_arr['mista_id_arr'];
        $nalezena_sablona_obj = $udalosti_sablony_arr['nalezena_sablona_obj'];



        $akt_sablona_id = 0;
        if (is_object($nalezena_sablona_obj)) {
            $akt_sablona_id = $nalezena_sablona_obj->id;
        }


        $pocet_mist = count($mista_arr);

        $nadpis = 'Šablona';
        if (is_object($nalezena_sablona_obj)) {
            $nadpis = $nalezena_sablona_obj->nazev;
        }
        echo '<tr>';
        echo '<th>'.$nadpis.'</th>';
        foreach ($mista_arr as $misto) {
            echo '<th>';
            echo $misto;
            echo '</th>';
        }

        echo '</tr>';
        $dnesni_den_obj = new DateTime();
        $dnesni_den_str = $dnesni_den_obj->modify('Y-m-d');
        foreach ($dny_tydne_arr as $den_tydne) {
            $nadpis_dne = '';
            //$to_je_dnesni_den = false;

            switch ($den_tydne) {
                case 'PO':
                    $nadpis_dne = 'PONDĚLÍ ';
                    break;
                case 'UT':
                    $nadpis_dne = 'ÚTERÝ ';
                    break;
                case 'ST':
                    $nadpis_dne = 'STŘEDA ';
                    break;
                case 'CT':
                    $nadpis_dne = 'ČTVRTEK ';
                    break;
                case 'PA':
                    $nadpis_dne = 'PÁTEK ';
                    break;
                case 'SO':
                    $nadpis_dne = 'SOBOTA ';
                    break;
                case 'NE':
                    $nadpis_dne = 'NEDĚLE ';
                    break;
            }
            echo '<tr>';
            echo '<th class="den_obyc">';
            //prvni bunka obsahuje titulek dne
            echo $nadpis_dne;
            echo '</th>';

            foreach ($mista_arr as $misto) {
                echo '<td class="den_obyc">';
                $bunka_arr = $bunky_arr[$den_tydne][$misto];
                $text_bunky = '';
                //$pocet_polozek = 0;
                foreach($bunka_arr as $udalost) {
                    $text_udalosti = '';
                    if (is_object($udalost)) {
                        $text_udalosti = '<div class="udalost">';
                        $zvyrazneni = $udalost->zvyrazneni;
                        $cas_old = $udalost->cas;
                        $cas_konec = '';
                        $cas_konec_bool_int = strpos($udalost->cas_konec, '00:00');
                        if (($cas_konec_bool_int === false) || ($cas_konec_bool_int !== 0)) {
                            $date_time_obj2 = date_create($dnesni_den_str.' '.$udalost->cas_konec);
                            if (is_object($date_time_obj2)) {
                                $cas_konec = $date_time_obj2->format('G:i');
                            }
                        }
                        $date_time_obj = date_create($dnesni_den_str.' '.$cas_old);
                        if (is_object($date_time_obj)) {
                            $cas_new = $date_time_obj->format('G:i');
                        } else {
                            $cas_new = 'hh:mm';
                        }
                        $link_uprav = JRoute::_( 'index.php?option=com_ohlasky&controller=udalost_sabl&task=edit&cid[]='. $udalost->id );
                        if (empty($cas_konec)) {
                            if ($zvyrazneni == 1) {
                                $text_udalosti = $text_udalosti."<b><a href=\"".$link_uprav."\">".$cas_new.'</a></b><br /><b>'.$udalost->hruby_popis.'<br /></b>';
                            } else {
                                $text_udalosti = $text_udalosti."<a href=\"".$link_uprav."\">".$cas_new.'</a><br />'.$udalost->hruby_popis.'<br />';
                            }
                        } else {
                            if ($zvyrazneni == 1) {
                                $text_udalosti = $text_udalosti."<b><a href=\"".$link_uprav."\">".$cas_new.' - '.$cas_konec.'</a></b><br /><b>'.$udalost->hruby_popis.'<br /></b>';
                            } else {
                                $text_udalosti = $text_udalosti."<a href=\"".$link_uprav."\">".$cas_new.' - '.$cas_konec.'</a><br />'.$udalost->hruby_popis.'<br />';
                            }
                        }
                        $text_udalosti = $text_udalosti.'</div>';

                    } else {
                        $text_bunky = $udalost;
                    }
                    $text_bunky = $text_bunky.$text_udalosti;
                }
                echo $text_bunky;

                $pridat_dnu_int = (intval($den_tydne) - 1);

                $id = 0;
                $akt_den_tydne = $den_tydne;
                $akt_misto_id = $mista_id_arr[$misto];
                $link_add = JRoute::_( 'index.php?option=com_ohlasky&controller=udalost_sabl&task=add&cid[]=0&den_tydne=' .$akt_den_tydne.'&misto_id='.$akt_misto_id.'&sablona_id='.$akt_sablona_id );
                echo '<br>';
                echo "<a href=\"".$link_add."\">".JHTML::_('image.administrator', 'pridat_udalost.png','/components/com_ohlasky/images/')."  </a>";
                echo '</td>';
            }
            echo '</tr>';
        }


        ?>
</table>
<?php





}

$link_tydny_ohlasek = JRoute::_( 'index.php?option=com_ohlasky&view=ohlaskys');

?>
<table class="dolni">
    <tr>
        <th class="dolni">
            <a href="<?php echo $link_tydny_ohlasek; ?>"><?php echo JHTML::_('image.administrator', 'hlavni_menu.png','/components/com_ohlasky/images/'); ?> </a>
        </th>

    </tr>
</table>


